clear all;

cd ..; cd ..; cd ..;
load('code_main_model\6_implied_w_r\computation_results\data.mat','credit','pdf_B_forward','d','Z','Y');
cd 'code_figure_table\OA\Figure OA12';

credit=credit(1,:);
Y=Y(1,:);
mktsize=squeeze(sum(pdf_B_forward(1,:,:,:,:),[3,4,5]));

credit=credit./mktsize;
Y=Y./mktsize;

d=d(1,:);

mkt=find(Z==median(Z));

credit=credit(mkt);
Y=Y(mkt);
d=d(mkt);


[~,id]=sort(d);

d=d(id);
credit=credit(id);
Y=Y(id);

pop_den_median=150;
y_output=pop_den_median*Y;
y_credit=pop_den_median*credit;

x=d;

figure;
plot(x,y_credit);

figure;
plot(x,y_output);

save('CF.mat','x','y_credit','y_output');